Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: expose complete stateStore as a slot prop #38

Merged
merged 7 commits into from
Nov 20, 2023

Conversation

Not-Jayden
Copy link
Contributor

Expose state store as a solution to debouncing search updates with the updateState method

Closes #37

Copy link

changeset-bot bot commented Nov 19, 2023

🦋 Changeset detected

Latest commit: 5bb899f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
cmdk-sv Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Nov 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cmdk-sv ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2023 6:06pm

Copy link
Owner

@huntabyte huntabyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wouldn't mind updating the README for this change as well, just so others know it's out there!

@@ -86,13 +86,13 @@
</script>

{#if asChild}
<slot {root} label={{ attrs: labelAttrs }} />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move these into a reactive slotProps prop, so something like:

<script lang="ts">
	$: slotProps = {
		root,
		label: { attrs: labelAttrs },
		stateStore,
		state: $stateStore,
	}
</script>

If we're going to pass stores as slot props I think they should be suffixed with Store and then we can also pass the value of the store as the state prop.

@Not-Jayden
Copy link
Contributor Author

@huntabyte On it 👌

Comment on lines +122 to +130
This component also exposes two additional slot props for `state` (the current reactive value of the command state) and `stateStore` (the underlying writable state store). These can be used to implement more advanced use cases, such as debouncing the search updates with the `stateStore.updateState` method:

```svelte
<Command.Root {state} let:stateStore>
{@const handleUpdateState = debounce(stateStore.updateState, 200)}
<CustomCommandInput {handleUpdateState} />
</Command.Root>
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to keep it relatively brief, as I don't imagine it will be super commonly used. Also writing this very late at night so please proof-read and edit as you please 😅

Copy link
Owner

@huntabyte huntabyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@huntabyte huntabyte merged commit d5cc1c1 into huntabyte:main Nov 20, 2023
4 checks passed
@github-actions github-actions bot mentioned this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: support debouncing search value changes
2 participants